package game.editer.data;

import game.editer.view.AlertView;
import game.data.XlsData;
import VectorMath.degrees;
import hx.display.Label;
import openfl.net.SharedObject;
#if electron
import electron.renderer.IpcRenderer;
#end
/**
 * 设置参数
 */
class SettingData {
	/**
	 * 设置配置
	 */
	public static var config:SettingDataConfig = {};

	public static var currentLanguage:String;

	public static function init():Void {
		config = SharedObject.getLocal("config").data;
		if (config.language == null) {
			config.language = "zh";
		}
		currentLanguage = config.language;
		updateConfig();
	}

	/**
	 * 储存
	 */
	public static function save():Void {
		SharedObject.getLocal("config").flush();
		if (currentLanguage != config.language) {
			AlertView.showView("提示", "语言已切换，重启后生效！", function(tag) {
				IpcRenderer.send("relunch");
			});
		}
	}

	public static function updateConfig():Void {
		Label.onGlobalCharFilter = (text) -> {
			// return "TEST";
			switch SettingData.config.language {
				case "zh":
					return text;
				case "en":
					var data = XlsData.lang.getDataByZh(text);
					if (data != null) {
						return data.en;
					}
				default:
					return text;
			}
			return text;
		}
	}
}

typedef SettingDataConfig = {
	?language:String,
}
